package com.CST.controller.ys;

import com.CST.common.api.ResultObject;
import com.CST.dto.ys.NumAndYardDTO;
import com.CST.dto.ys.YsBusinessBudgetDTO;
import com.CST.entity.ys.YsAccountDetail;
import com.CST.service.ys.YsBusinessBudgetService;
import com.CST.vo.ys.YsAccountDetailBusinessOrManageVO;
import com.CST.vo.ys.YsBusinessAccountVO;
import com.CST.vo.ys.YsModifyRecordVO;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 业务预算执行管理
 * @author cw
 */
@Api(tags={"业务预算执行管理"})
@RestController
@RequestMapping("/ysBusinessBudget")
public class YsBusinessBudgetController {
    @Autowired
    private YsBusinessBudgetService ysBusinessBudgetService;

    @ApiOperation("查询业务预算")
    @PostMapping("/getBusinessBudgetList")
    public ResultObject<YsBusinessAccountVO> getBusinessBudgetList(@RequestBody YsBusinessBudgetDTO ysBusinessBudgetDto){
        return ResultObject.success(ysBusinessBudgetService.getBusinessBudgetInfo(ysBusinessBudgetDto));
    }

    @ApiOperation("新增业务凭证")
    @PostMapping("/insertBusinessBudget")
    public ResultObject<Boolean> insertBusinessBudget(@RequestBody YsAccountDetail ysAccountDetail){
        return ResultObject.success(ysBusinessBudgetService.insertBusinessBudget(ysAccountDetail));
    }

    @ApiOperation("编辑回显数据")
    @GetMapping("/getInfoByNum/{id}")
    public ResultObject<YsAccountDetailBusinessOrManageVO> getInfoByNum(@PathVariable Integer id){
        return ResultObject.success(ysBusinessBudgetService.selectInfoByNum(id));
    }

    @ApiOperation("更新业务凭证")
    @PostMapping("/updateBusinessAccountByNum")
    public ResultObject<Integer> updateBusinessAccountByNum(@RequestBody YsAccountDetail ysAccountDetail, HttpServletRequest request){
        return ResultObject.success(ysBusinessBudgetService.updateBusinessAccountByNum(ysAccountDetail,request));
    }

    @ApiOperation("删除业务凭证")
    @GetMapping("/deleteByNum/{id}")
    public ResultObject<Boolean> deleteByNum(@PathVariable Integer id){
        return ResultObject.success(ysBusinessBudgetService.deleteByNum(id));
    }

    @ApiOperation("发布数据")
    @PostMapping("/releaseData")
    public ResultObject<Boolean> releaseData(@RequestBody YsBusinessBudgetDTO ysBusinessBudgetDto){
        return ResultObject.success(ysBusinessBudgetService.releaseData(ysBusinessBudgetDto));
    }

    @ApiOperation("导出")
    @PostMapping("/exportExcelYsBusinessBudget")
    public void exportExcelYsBusinessBudget(HttpServletResponse response, @RequestBody YsBusinessBudgetDTO dto) {
        ysBusinessBudgetService.exportExcelYsBusinessBudget(response, dto);
    }

    @ApiOperation("查询修订记录")
    @PostMapping("/getModifyRecordList")
    public ResultObject<PageInfo<YsModifyRecordVO>> getModifyRecordList(@RequestBody YsBusinessBudgetDTO ysBusinessBudgetDto){
        return ResultObject.success(ysBusinessBudgetService.getModifyRecordList(ysBusinessBudgetDto));
    }

    @ApiOperation("撤销")
    @PostMapping("/revokeRecord")
    public ResultObject<Boolean> revokeRecord(@RequestBody NumAndYardDTO dto){
        return ResultObject.success(ysBusinessBudgetService.revokeRecord(dto));
    }
}
